@extends('admin.main')
@section('body')
    <div class="main-title">
        <h2>{{isset($info['id']) ? '修改':'添加'}}押金</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form action="" method="post" class="form-horizontal">
                <div class="form-item">
                    <label class="item-label">
                        店&nbsp;&nbsp;铺&nbsp;&nbsp;名&nbsp;&nbsp;称 ：<span class="check-tips">{{$shop['shop_name']}}</span>
                    </label>
                </div>
                <div class="form-item">
                    <label class="item-label">
                        客&nbsp;&nbsp;户&nbsp;&nbsp;名&nbsp;&nbsp;称 ：<span class="check-tips">{{$member['name']}}</span>
                    </label>
                </div>
                <div class="form-item">
                    <label class="item-label">
                        客&nbsp;&nbsp;户&nbsp;&nbsp;电&nbsp;&nbsp;话 ：<span class="check-tips">{{$member['mobile']}}</span>
                    </label>
                </div>
                <div class="form-item">
                    <label class="item-label">
                        客&nbsp;&nbsp;户&nbsp;&nbsp;地&nbsp;&nbsp;址 ：<span class="check-tips">{{$member['address']}}</span>
                    </label>
                </div>
                @if(isset($info))
                    <div style="float: left;">
                        <div class="form-item">
                            <label class="item-label" style="color:#aaa">
                                水桶丢损赔付：<span class="check-tips">{{isset($info['lose_pay']) ? $info['lose_pay'] : ''}}</span>
                            </label>
                        </div>
                        <div class="form-item">
                            <label class="item-label" style="color:#aaa">
                                自&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;桶：
                            <span class="check-tips">
                                       {{isset($info['self_bucket']) ? $info['self_bucket'] : ''}}
                            </span>
                                &nbsp;&nbsp;水桶品牌：
                            <span class="check-tips">
                               @if(count($bucketData))
                                    @foreach($bucketData as $v)
                                        @if(isset($info) && $info['self_bucket_category'] == $v['bucket_category_id'])
                                            {{$v['category']['title']}}
                                        @endif
                                    @endforeach
                                @endif
                            </span>
                            </label>
                        </div>
                        <div class="form-item">
                            <label class="item-label" style="color:#aaa">
                                押&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;桶：
                            <span class="check-tips">
                                {{isset($info['cash_bucket']) ? $info['cash_bucket'] : ''}}
                            </span>
                                &nbsp;&nbsp;水桶品牌：
                            <span class="check-tips">
                                @if(count($bucketData))
                                    @foreach($bucketData as $v)
                                        @if(isset($info) && $info['cash_bucket_category'] == $v['bucket_category_id'])
                                            {{$v['category']['title']}}
                                        @endif
                                    @endforeach
                                @endif
                            </span>
                            </label>
                        </div>
                        @if(isset($info))
                            <div class="form-item">
                                <label class="item-label" style="color:#aaa">
                                    借&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;桶：
                            <span class="check-tips">
                                {{$member['borrow_bucket_num']}}
                            </span>
                                </label>
                            </div>
                        @endif
                        <div class="form-item">
                            <label class="item-label" style="color:#aaa">
                                水&nbsp;&nbsp;桶&nbsp;&nbsp;押&nbsp;&nbsp;金 ：
                            <span class="check-tips">
                                       {{isset($info['cash']) ? $info['cash'] : ''}}
                            </span>
                            </label>
                        </div>
                        <div class="form-item">
                            <label class="item-label" style="color:#aaa">
                                押&nbsp;&nbsp;饮&nbsp;&nbsp;水&nbsp;&nbsp;机 ：
                            <span class="check-tips">
                                       {{isset($info['water_dispenser']) ? $info['water_dispenser'] : ''}}
                            </span>
                            </label>
                        </div>
                        <div class="form-item">
                            <label class="item-label" style="color:#aaa">
                                饮 水 机 押 金：
                            <span class="check-tips">
                                       {{isset($info['water_dispenser_cash']) ? $info['water_dispenser_cash'] : ''}}
                            </span>
                            </label>
                        </div>
                        <div class="form-item">
                            <label class="item-label" style="color:#aaa">
                                备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：
                            <span class="check-tips">
                                       {{isset($info['description']) ? $info['description'] : ''}}
                            </span>
                            </label>
                        </div>
                    </div>
                @endif
                <div  @if(isset($info)) style="float: left;margin-left: 50px;" @endif>
                    <div class="form-item">
                        <label class="item-label">
                            水桶丢损赔付：
                            <span class="check-tips">
                                <input type="text" name="lose_pay" class="text input-small"
                                       value="{{isset($info['lose_pay']) ? $info['lose_pay'] : ''}}">
                            </span>
                        </label>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            自&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;桶：
                            <span class="check-tips">
                                <input type="text" name="self_bucket" class="text input-small"
                                       value="{{isset($info['self_bucket']) ? $info['self_bucket'] : ''}}">
                            </span>
                            水桶品牌：
                            <span class="check-tips">
                                <select name="self_bucket_category" id="self_bucket_category">
                                       @if(count($bucketData))
                                        @foreach($bucketData as $v)
                                            <option value="{{$v['bucket_category_id']}}" @if(isset($info) && $info['self_bucket_category'] == $v['bucket_category_id']) selected @endif>{{$v['category']['title']}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </span>
                        </label>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            押&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;桶：
                            <span class="check-tips">
                                <input type="text" name="cash_bucket" class="text input-small"
                                       value="{{isset($info['cash_bucket']) ? $info['cash_bucket'] : ''}}">
                            </span>
                            水桶品牌：
                            <span class="check-tips">
                                <select name="cash_bucket_category" id="cash_bucket_category">
                                       @if(count($bucketData))
                                        @foreach($bucketData as $v)
                                            <option value="{{$v['bucket_category_id']}}" @if(isset($info) && $info['cash_bucket_category'] == $v['bucket_category_id']) selected @endif>{{$v['category']['title']}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </span>
                        </label>
                    </div>
                    @if(isset($info))
                        <div class="form-item">
                            <label class="item-label">
                                借&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;桶：
                            <span class="check-tips">
                                {{$member['borrow_bucket_num']}}
                            </span>
                            </label>
                        </div>
                    @endif
                    <div class="form-item">
                        <label class="item-label">
                            水&nbsp;&nbsp;桶&nbsp;&nbsp;押&nbsp;&nbsp;金 ：
                            <span class="check-tips">
                                <input type="text" name="cash" class="text input-small"
                                       value="{{isset($info['cash']) ? $info['cash'] : ''}}">
                            </span>
                        </label>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            押&nbsp;&nbsp;饮&nbsp;&nbsp;水&nbsp;&nbsp;机 ：
                            <span class="check-tips">
                                <input type="text" name="water_dispenser" class="text input-small"
                                       value="{{isset($info['water_dispenser']) ? $info['water_dispenser'] : ''}}">
                            </span>
                        </label>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            饮 水 机 押 金：
                            <span class="check-tips">
                                <input type="text" name="water_dispenser_cash" class="text input-small"
                                       value="{{isset($info['water_dispenser_cash']) ? $info['water_dispenser_cash'] : ''}}">
                            </span>
                        </label>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：
                            <span class="check-tips">
                                <input type="text" name="description" class="text input-large"
                                       value="{{isset($info['description']) ? $info['description'] : ''}}">
                            </span>
                        </label>
                    </div>
                </div>
                @if(isset($info))
                    <div class="form-item" style="clear: both">
                        <label class="item-label">
                            是&nbsp;&nbsp;否&nbsp;&nbsp;退&nbsp;&nbsp;还 ：<span class="check-tips">（注意：该操作不可逆）</span>
                        </label>
                        <div class="controls">
                            <label class="inline radio"><input type="radio" name="status" value="0" @if($info['status'] == 0 ) checked @endif>否</label>
                            <label class="inline radio"><input type="radio" name="status" value="1" @if($info['status'] == 1 ) checked @endif>是</label>
                        </div>
                    </div>
                @endif
                <div class="form-item" style="clear: both">
                    <input type="hidden" name="id" value="{{isset($info['id']) ? $info['id'] : ''}}">
                    <input type="hidden" name="mid" value="{{$member['id']}}">
                    <input type="hidden" name="shop_id" value="{{$member['shop_id']}}">
                    <input type="hidden" name="admin_id" value="{{$member['admin_id']}}">
                    <button type="submit" id="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定
                    </button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                </div>
            </form>
        </div>
    </div>
@endsection

@section('script')
    <script>
        var categoryData = JSON.parse('{!! json_encode($bucketData) !!}');
        var self_bucket_category = parseInt('{{isset($info) ? $info['self_bucket_category'] : 0}}}');
        var cash_bucket_category = parseInt('{{isset($info) ? $info['cash_bucket_category'] : 0}}}');
        $(window).ready(function () {
            var shop_id = $('#shop_id').val();
            changeOptions(categoryData, shop_id, 'self_bucket_category', self_bucket_category)
            changeOptions(categoryData, shop_id, 'cash_bucket_category', cash_bucket_category)
        });
        function changeOptions(categoryData, shop_id, target, category_id) {
            var options = '';
            for (var i in categoryData) {
                if (categoryData[i].shop_id == shop_id) {
                    if (category_id == categoryData[i].id) {
                        options += "<option value='" + categoryData[i].id + "' selected>" + categoryData[i].category.title + "</option>";
                    } else {
                        options += "<option value='" + categoryData[i].id + "'>" + categoryData[i].category.title + "</option>";
                    }
                }
            }
            $("#" + target).append(options);
        }
        $('#shop_id').change(function () {
            var shop_id = $(this).val();
            $("#self_bucket_category").empty();
            $("#cash_bucket_category").empty();
            changeOptions(categoryData, shop_id, 'self_bucket_category', 0)
            changeOptions(categoryData, shop_id, 'cash_bucket_category', 0)
        });
    </script>
@endsection
